import {BaseRenderer} from "./base-renderer";
import {FormRenderer} from "./form-renderer";
import {TableRenderer} from "./table-renderer";
import {ProgramRenderer} from "./program-renderer";
import {CustomerRenderer} from "./customer-renderer.ts";
import type {RenderType} from '../type/index.ts';

/**
 * 渲染器工厂
 */
export class RendererFactory {
    private static renderers: Map<RenderType, BaseRenderer> = new Map();

    /**
     * 声明渲染器
     */
    static {
        this.register('form', new FormRenderer());
        this.register('table', new TableRenderer());
        this.register('program', new ProgramRenderer());
        this.register('customer', new CustomerRenderer())
    }

    /**
     * 注册渲染器
     */
    static register(type: RenderType, renderer: BaseRenderer) {
        this.renderers.set(type, renderer);
    }

    /**
     * 根据组件类型获取对应的渲染器
     */
    static getRenderer(renderType: RenderType = "customer"): BaseRenderer {
        switch (renderType) {
            case 'form':
                return this.renderers.get('form')!;
            case 'table':
                return this.renderers.get('table')!;
            case 'program':
                return this.renderers.get('program')!;
            case 'customer':
                return this.renderers.get('customer')!;
            default:
                return this.renderers.get('customer')!;
        }
    }
}